package com.zy;

import java.util.concurrent.TimeUnit;

/**
 * @Author zhaoyi
 * @date 2019/10/23
 * 对应测试类的八个方法
 */
public class Phone {

    private String name;

    public Phone(String name) {
        this.name = name;
    }

    public synchronized void sendMsg() throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        System.out.println("[短信] 你好中国移动提醒你余额不足,来自你的" + name + Thread.currentThread().getName());
    }

    public synchronized void sendWeiXin() {
        System.out.println("[微信] 收到红包200元,来自你的" + name + Thread.currentThread().getName());
    }

    public static synchronized void sendStaticMsg() throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        System.out.println("[static] sleep "  + Thread.currentThread().getName());
    }

    public static synchronized void sendStaticWX() {
        System.out.println("[static] normal "  + Thread.currentThread().getName());
    }

    public synchronized void sendEmail() {
        System.out.println("[Email] 招商银信用卡行账单邮件,来自你的" + " 线程名称" + Thread.currentThread().getName());
    }

    public void sayHello() {
        System.out.println("[非同步招呼] 亲, 双十一到了,来自你的" + " 线程名称" + Thread.currentThread().getName());
    }

    public void saySay() {
        System.out.println("进入非同方法");
        synchronized (this.getClass()){
            System.out.println("====== 获取Class锁 ======");
        }
        System.out.println("执行结束");
    }


}
